// import { useToken } from '@/composables/useToken'
// import { DefaultToken } from '@/constants'
import { defineStore } from 'pinia'

export const useAuthStore = defineStore('auth', () => {
  
  const openid = ref('')
  const token = ref('')
  const sessionid = ref('')
  const loginMode = ref('')
  // 登录后需要跳转的页面
  const backAfterLogin = ref('')

  const logout = () => {
    token.value = ''
    sessionid.value = ''
    loginMode.value = ''
  }

  const navigateToLogin = () => {
    // 获取当前页面路径
    const pages: any[] = getCurrentPages()
    const currentPageFullPath = pages[0].$page.fullPath
    // 将页面路径存入登录后需要跳转的页面
    backAfterLogin.value = currentPageFullPath
    // 然后跳转登录页
    uni.navigateTo({
      url: '/pages/login/index'
    })
  }
  
  return {
    openid,
    token,
    sessionid,
    loginMode,
    backAfterLogin,
    logout,
    navigateToLogin
  }
})
